<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>构造函数</title>
	</head>
	<body>
		<script type="text/javascript">
			//通过构造函数，创建出一些具有相同特征的对象
			
			//1、内置构造元素
			var obj1=new Object();
			var str1=new String("hi");
			console.log(obj1.constructor);
			console.log(str1.constructor);
			
			//若不用构造函数，定义2个具有相同属性的对象
			var o1={
				"name":"lily",
				"age":14,
				sayHi:function(){console.log("hello");}
			};
			var o2={
				"name":"tom",
				"age":15,
				sayHi:function(){console.log("hello");}
			};
			//2、自定义构造函数：创建出一些具有相同特征的对象
			function Person(name,age){
				this.name=name;
			this.age=age;
			this.sayHi=function(){console.log("hello");};
			}
			 var p1=new Person('zhangsan',20);
			 var p2=new Person('lisi',24)
			 console.log(p1.constructor);
			 console.log(p1.constructor==p2.constructor);
			
		</script>
	</body>
</html>
